#include <cstdio>
#include <cstring>

//避免动态分配
struct node {
    node* left_child;
    node* right_child;
    char data;
} Tree[50];

int node_num = 0;
char str1[30], str2[30];

node* create_tree()
{
    Tree[node_num].left_child = Tree[node_num].right_child = NULL;
    return &Tree[node_num++];
}

node* build_tree(int start1, int end1, int start2, int end2)
{
    node* return_node = create_tree();
    return_node->data = str1[start1];
    int root_index;
    for (int i = start2; i <= end2; i++) {
        if (str2[i] == str1[start1]) {
            root_index = i;
        }
    }
    if (root_index != start2) {
        //下标确定三个可以算出第4个
        return_node->left_child = build_tree(start1 + 1, root_index - start2 + start1, start2, root_index - 1);
    }
    if (root_index != end2) {
        return_node->right_child = build_tree(end1 + root_index + 1 - end2, end1, root_index + 1, end2);
    }
    return return_node;
}

void post_treavers(node* root_node)
{
    if (root_node->left_child != NULL)
        post_treavers(root_node->left_child);
    if (root_node->right_child != NULL)
        post_treavers(root_node->right_child);
    printf("%c", root_node->data);
}

int main(int argc, char const* argv[])
{   //该题要求以EOF结尾，即不能直接输入
    while (scanf("%s", str1) != EOF) {
        scanf("%s", str2);
        node_num = 0;
        int length1 = strlen(str1);
        int length2 = strlen(str2);
        node* root_node = build_tree(0, length1 - 1, 0, length2 - 1);
        post_treavers(root_node);
        printf("\n");
    }
    return 0;
}